using System;
using System.Collections.Generic;
using System.Text;
using Rapier.Kodachi.Shared;
using System.Drawing;

namespace Rapier.Kodachi.Eightball.Actions
{
    public class Shake : Action
    {
       private Bitmap eightBallImage; 

        #region Constructor
        public Shake(Plugin plugin)
            : base(plugin, "Rapier.Kodachi.Eightball.Shake", "Ask the 8 Ball", "Ask a question, then shake the eight ball for an answer!")
        {
            eightBallImage = (Bitmap)Rapier.Kodachi.Eightball.Properties.Resources.EightBall;
            this.DefaultIndirectTextMode = true;
            this.IndirectItemUse = IndirectItemUse.None;
            GetImage = delegate()
            {
               return eightBallImage;
            };
        }
        #endregion

        #region Action Members
        public override void Execute(Item[] directItems, Item[] indirectItems)
        {
            bool success = false;

            if (directItems.Length > 0 && directItems[0].Properties.ContainsKey("Text"))
            {
                if (directItems[0].Properties["Text"].ToString().EndsWith("?"))
                {
                    SendEightballNotification();
                    success = true;
                }
            }

            if (!success)
            {
                NotificationPackage package = new NotificationPackage();
                package.Caption = "The 8 Ball Says...";
                package.Image = new System.Drawing.Bitmap((Bitmap)Rapier.Kodachi.Eightball.Properties.Resources.ResourceManager.GetObject("EightBall"), new Size(48, 48));
                package.Message = "\nPlease enter text in the form of a question...";
                Plugin.Host.Notify(package);
            }
        }

        public override bool IsValidIndirect(Item indirectItem)
        {
            return false;
        }

        public override bool IsValidDirect(Item directItem)
        {
            return directItem.Properties.ContainsKey("Text") && directItem.Properties.Count == 1;
        }
        #endregion

        #region Private Methods
        private void SendEightballNotification()
        {
            Random random = new Random();
            int messageID = random.Next(0,20);

            NotificationPackage package = new NotificationPackage();
            package.Caption = "The 8 Ball Says...";
            package.Image = new System.Drawing.Bitmap((Bitmap)Rapier.Kodachi.Eightball.Properties.Resources.ResourceManager.GetObject("EightBall"),new Size(48,48));

            package.Message = "\n";

            #region Switch on messages (10 positive, 5 neutral, 5 negative)
            switch (messageID)
            {
                case 0:
                    package.Message += "Signs point to Yes.";
                    break;
                case 1:
                    package.Message += "Yes.";
                    break;
                case 2:
                    package.Message += "Most likely.";
                    break;
                case 3:
                    package.Message += "Without a doubt.";
                    break;
                case 4:
                    package.Message += "Yes - Definitely.";
                    break;
                case 5:
                    package.Message += "As I see it, Yes.";
                    break;
                case 6:
                    package.Message += "You may rely on it.";
                    break;
                case 7:
                    package.Message += "Outlook good.";
                    break;
                case 8:
                    package.Message += "It is certain.";
                    break;
                case 9:
                    package.Message += "It is decidedly so.";
                    break;
                case 10:
                    package.Message += "Reply hazy, try again.";
                    break;
                case 11:
                    package.Message += "Better not tell you now.";
                    break;
                case 12:
                    package.Message += "Ask again later.";
                    break;
                case 13:
                    package.Message += "Concentrate and ask again.";
                    break;
                case 14:
                    package.Message += "Cannot predict now.";
                    break;
                case 15:
                    package.Message += "My sources say no.";
                    break;
                case 16:
                    package.Message += "Very doubtful.";
                    break;
                case 17:
                    package.Message += "My reply is no.";
                    break;
                case 18:
                    package.Message += "Outlook not so good.";
                    break;
                case 19:
                    package.Message += "Don't count on it.";
                    break;
                default:
                    package.Message += "Kodachi will rule the world!";
                    break;
            }
            #endregion

            Plugin.Host.Notify(package);
        }
        #endregion
    }
}
